var util = require('../../utils/util.js')

Page({
    data: {
        list: [
            {
                avatar: "../../resources/avatar/1.png",
                date: "2022/04/18 11:20:47",
                title: '《相见欢 · 阴》',
                author: '张克',
                text: '心逐南云湍涌，风萧萧，孤寂凭栏处独望重楼。\n峰峦聚，引雷鸣，雨将至，祈愿晴空万里合家兴。',
                id: 0

            },
            {
                avatar: "../../resources/avatar/2.png",
                date: "2022/04/18 10:30:20",
                title: '《诉晴》',
                author: '张克',
                text: '晓晴悦目时，\n日曜半方塘。\n波光何粼粼，\n不及游子心。',
                id: 1
            },
            {
                avatar: "../../resources/avatar/3.png",
                date: "2022/04/18 10:20:36",
                title: '《天一》',
                author: '张克',
                text: '周阁门内无轴隔，至宾堂下满志彬。\n胸有成竹笔剑戟，旭日东升立坤乾。\n修整鸣金声扬扬，行人过往去匆匆。\n凯旋班师见天子，万人空巷尽箪食。',
                id: 2
            }
        ]
    },

    onLoad() {
        if(wx.getStorageSync('userData').length != 0) {
            getApp().globalData.user=wx.getStorageSync('userData')
        }
        
        if (wx.getStorageSync('PostsData').length != 0) {
            let arr = wx.getStorageSync('PostsData')//从缓存中读入帖子数据
            getApp().globalData.postsdata = arr
            this.setData({
                list: arr
            })
        }
        else {
            var arr = getApp().globalData.postsdata
            this.setData({
                list: arr
            })
        }
        var time = util.formatTime(new Date())
        //time=time.split(" ")[0].split("/")
        //console.log(time)
    },

    skipTravelDetails(e) {
        let id = e.currentTarget.dataset.id //获取点击产品时拿到的id，就是data-id传过来的值
        getApp().globalData.postsdata = this.data.list//将帖子数据存入全局变量

        wx.navigateTo({
            url: "../posts/posts?id=" + id,
        })
    },

    FlowPost() {   //浮动图标跳转
        wx.navigateTo({
            url: "../post/post"
        })
    }
})